package com.ruoyi.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DbDataInfo;
import com.ruoyi.system.service.DbDataInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 测试业务逻辑数据Controller
 * 
 * @author ruoyi
 * @date 2023-04-20
 */
@Controller
@RequestMapping("/system/dataInfo")
public class DbDataInfoController extends BaseController {

    private String prefix = "system/dataInfo";

    @Resource
    private DbDataInfoService dbDataInfoService;

    @RequiresPermissions("system:dataInfo:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询测试业务逻辑数据列表
     */
    @RequiresPermissions("system:dataInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DbDataInfo dbDataInfo)
    {
        startPage();
        List<DbDataInfo> list = dbDataInfoService.selectDbDataInfoList(dbDataInfo);
        return getDataTable(list);
    }

    /**
     * 导出测试业务逻辑数据列表
     */
    @RequiresPermissions("system:dataInfo:export")
    @Log(title = "测试业务逻辑数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DbDataInfo dbDataInfo)
    {
        List<DbDataInfo> list = dbDataInfoService.selectDbDataInfoList(dbDataInfo);
        ExcelUtil<DbDataInfo> util = new ExcelUtil<DbDataInfo>(DbDataInfo.class);
        return util.exportExcel(list, "测试业务逻辑数据数据");
    }

    /**
     * 新增测试业务逻辑数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存测试业务逻辑数据
     */
    @RequiresPermissions("system:dataInfo:add")
    @Log(title = "测试业务逻辑数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DbDataInfo dbDataInfo)
    {
        return toAjax(dbDataInfoService.insertDbDataInfo(dbDataInfo));
    }

    /**
     * 修改测试业务逻辑数据
     */
    @RequiresPermissions("system:dataInfo:edit")
    @GetMapping("/edit/{deptId}")
    public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
    {
        DbDataInfo dbDataInfo = dbDataInfoService.selectDbDataInfoByDeptId(deptId);
        mmap.put("dbDataInfo", dbDataInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存测试业务逻辑数据
     */
    @RequiresPermissions("system:dataInfo:edit")
    @Log(title = "测试业务逻辑数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DbDataInfo dbDataInfo)
    {
        return toAjax(dbDataInfoService.updateDbDataInfo(dbDataInfo));
    }

    /**
     * 删除测试业务逻辑数据
     */
    @RequiresPermissions("system:dataInfo:remove")
    @Log(title = "测试业务逻辑数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dbDataInfoService.deleteDbDataInfoByDeptIds(ids));
    }
}
